package com.gt.quality.system.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.collection.CollUtil;
import com.gt.quality.base.BaseCommonController;
import com.gt.quality.base.BaseCommonService;
import com.gt.quality.config.utils.UserStatus;
import com.gt.quality.system.entity.SysRole;
import com.gt.quality.base.pojo.Resp;
import com.gt.quality.system.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色信息表(SysRole)表控制层
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@RestController
@RequestMapping("sysRole")
@Tag(name = "角色管理")
public class SysRoleController  extends BaseCommonController<SysRole> {
    /**
     * 服务对象
     */
    private SysRoleService sysRoleService;

    @Autowired
    public void setSysRoleService(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    @Override
    public BaseCommonService<SysRole> getThisService() {
        return sysRoleService;
    }


   /**
     * 新增数据
     *
     * @param sysRole 实体对象
     * @return 新增结果
     */
    @PostMapping("/save")
	@Operation(summary = "新增数据")
    @SaCheckPermission("system:role:save")
    @Override
    public Resp<String> insert(@RequestBody SysRole sysRole) {
        sysRole.setStatus(UserStatus.OK.getCode());
        boolean save = this.sysRoleService.save(sysRole);
        String executeMsg = "id 是：" + sysRole.getRoleId();
        return save ? Resp.ok(executeMsg) : Resp.error(executeMsg);
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/dels")
	@Operation(summary = "删除数据-idList 主键结合")
    @SaCheckPermission("system:role:del")
    @Override
    public Resp<String> delete(@RequestParam("idList") List<Long> idList) {
        if (CollUtil.isNotEmpty(idList)){
            sysRoleService.checkUserBindRole(idList);
        }
        boolean delNumber = this.sysRoleService.warnDeleteOperation(idList);
        String executeMsg = "idList 是：" + idList;
        return delNumber ? Resp.ok(executeMsg) : Resp.error(executeMsg);
    }

    @Override
    protected boolean isSuperExcel() {
        return false;
    }
}
